
package com.jf.cloud.order.task;


import com.jf.cloud.api.feign.SearchOrderRefundTaskFeignClient;
import com.jf.cloud.common.exception.LuckException;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 退款订单定时任务
 *
 * @author zz
 */
@Component
public class OrderRefundTask {

    @Autowired
    private SearchOrderRefundTaskFeignClient searchOrderRefundTaskFeignClient;

    /**
     * 取消申请超时的订单，无论该超时订单处于任何状态
     */
    @XxlJob("cancelWhenTimeOut")
    public void cancelWhenTimeOut() {
        XxlJobHelper.log("取消申请超时的订单，无论该超时订单处于任何状态");

        ServerResponseEntity serverResponseEntity = searchOrderRefundTaskFeignClient.cancelWhenTimeOut();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }

    /**
     * 退款临近超时提醒,每12小时执行发送一次的提醒
     */
    @XxlJob("pressProximityTimeOutOrder")
    public void pressProximityTimeOutOrder() {
        XxlJobHelper.log("退款临近超时提醒,每12小时执行发送一次的提醒");
        ServerResponseEntity serverResponseEntity = searchOrderRefundTaskFeignClient.pressProximityTimeOutOrder();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }

}
